{% extends "base.html" %}

{% block content %}
<div class="row">
    <div class="col-md-8 mx-auto">
        <div class="card">
            <div class="card-header bg-primary text-white">
                <h4 class="mb-0">镜像传输</h4>
            </div>
            <div class="card-body">
                <form id="transferForm">
                    <div class="mb-3">
                        <label for="imageName" class="form-label">镜像地址</label>
                        <input type="text" class="form-control" id="imageName" 
                               placeholder="例如: nginx:latest 或 registry.example.com/nginx:latest" required>
                        <div class="form-text">请输入完整的镜像名称，包含标签或版本号</div>
                    </div>
                    
                    <div class="mb-3">
                        <label for="targetServer" class="form-label">目标服务器</label>
                        <select class="form-select" id="targetServer" required>
                            <option value="">选择目标服务器</option>
                            {% for server in servers %}
                            <option value="{{ server.id }}">{{ server.name }} ({{ server.host }})</option>
                            {% endfor %}
                        </select>
                    </div>
                    
                    <div class="mb-3">
                        <label for="targetPath" class="form-label">目标路径</label>
                        <input type="text" class="form-control" id="targetPath" 
                               placeholder="例如: /home/user/images/nginx.tar" required>
                        <div class="form-text">镜像将保存到目标服务器的指定路径</div>
                    </div>
                    
                    <button type="submit" class="btn btn-primary">
                        <i class="fas fa-paper-plane me-2"></i>开始传输
                    </button>
                </form>
                
                <div id="progressArea" class="mt-4" style="display: none;">
                    <h5>传输进度</h5>
                    <div class="progress mb-3" style="height: 20px;">
                        <div id="progressBar" class="progress-bar progress-bar-striped progress-bar-animated" 
                             role="progressbar" style="width: 0%">
                            <span id="progressPercent">0%</span>
                        </div>
                    </div>
                    <div id="progressStatus" class="alert alert-info">
                        <i class="fas fa-info-circle me-2"></i>准备开始传输...
                    </div>
                    <div id="logOutput" class="bg-dark text-light p-3 rounded" style="height: 200px; overflow-y: auto; font-family: monospace;"></div>
                    <button id="restartButton" class="btn btn-secondary mt-3" style="display: none;">
                        <i class="fas fa-redo me-2"></i>重新开始
                    </button>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block extra_css %}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
.log-entry {
    margin-bottom: 5px;
    padding: 2px 0;
}

.log-entry .timestamp {
    color: #888;
    margin-right: 10px;
}

.log-entry .log-info {
    color: #17a2b8;
}

.log-entry .log-warning {
    color: #ffc107;
}

.log-entry .log-error {
    color: #dc3545;
}

.loading-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 5px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
</style>
{% endblock %}

{% block extra_js %}
<script src="{{ url_for('static', filename='js/transfer.js') }}"></script>
{% endblock %}
